#!/bin/bash
#指定ip和dns服务器以及ssh初始化

#路径
CentOS_NETWORK_DIR="/etc/sysconfig/network-scripts/";
Ubuntu_NETWORK_DIR="/etc/network/interface"

DNS_OFFER(){
        cd $CentOS_NETWORK_DIR
        dns=`cat ifcfg-eth0 |grep "DNS1.*"`
        if [ "$dns" == "" ];then
                echo "IPADDR=\"192.168.137.22\"" >> ifcfg-eth0
                echo "NETMASK=\"255.255.255.0\"" >> ifcfg-eth0
                echo "GATEWAY=\"192.168.137.1\"" >> ifcfg-eth0
                echo "DNS1=\"192.168.3.242\"" >> ifcfg-eth0
                echo "nameserver 192.168.3.242" > /etc/resolv.conf
                echo "DNS指定成功"
        else
                echo "DNS已指定，不用重复操作"
        fi
}
DNS_OFFER
#08 设置ssh
init_ssh(){
                /bin/cp -f /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
                sed -i 's/#Port.*/Port 22/g' /etc/ssh/sshd_config                                    # 设置ssh监听端口
                sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config                 # root用户登录
                sed -i 's/#LoginGraceTime.*/LoginGraceTime 10m/g' /etc/ssh/sshd_config                  # 当用户连接ssh时多久没登录进来就断开
                sed -i 's/PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config    # 不允许使用密码登录，而是使用密钥登录
                sed -i 's/GSSAPIAuthentication.*/GSSAPIAuthentication yes/g' /etc/ssh/sshd_config        # 设置是否允许基于GSSAPI的用户认证
                sed -i 's/#UseDNS.*/UseDNS no/g' /etc/ssh/sshd_config                # 设置是否使用dns反向解析，这是用来优化登陆速度的 
                sed -i 's/#MaxStartups.*/MaxStartups 1000/g' /etc/ssh/sshd_config    # 设置同时允许几个尚未登入的联机，当用户连上ssh但并未输入密码即为所谓的联机 
                echo "ssh初始化配置成功"        
}
init_ssh
